import Immutable from 'immutable';
import { UPDATE_USERINFO_REDUX } from './actionTypes';
import preloadedState from '../../preloadedState';

const defaultUserInfo = preloadedState.get('userInfo');

function reducer(state = defaultUserInfo, action) {
    const { type, payload } = action;

    let newState = state;

    switch (type) {
        case UPDATE_USERINFO_REDUX:
            newState = newState.merge(Immutable.fromJS(payload));
            return newState;
        default:
            return state;
    }
}

export default reducer;
